package com.demoworld;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * Description
 * <p>
 * </p>
 * DATE 2018/5/19.
 *
 * @author liwei5.
 */
public class EnableLoggerInit implements ImportBeanDefinitionRegistrar {
    private BeanDefinitionRegistry beanDefinitionRegistry;

    private final String INITMETHOD = "init";
    private final String DESDROYMETHOD = "dispose";

    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
        this.beanDefinitionRegistry = beanDefinitionRegistry;
        init();
    }

    private void init() {
        BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(Logger.class)
                .setInitMethodName(INITMETHOD)
                .setDestroyMethodName(DESDROYMETHOD)
                .getBeanDefinition();
        this.beanDefinitionRegistry.registerBeanDefinition("Logger", beanDefinition);
    }
}
